package me.jessyan.mvparms.demo.mvp.ui.activity.car;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.example.xrecyclerview.XRecyclerView;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import me.jessyan.mvparms.demo.di.component.car.DaggerPayCostRcordComponent;
import me.jessyan.mvparms.demo.di.module.car.PayCostRcordModule;
import me.jessyan.mvparms.demo.mvp.contract.car.PayCostRcordContract;
import me.jessyan.mvparms.demo.mvp.presenter.car.PayCostRcordPresenter;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.ui.adapter.PayCostRecordAdapter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;


import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 缴费纪录
 */
public class PayCostRcordActivity extends BaseActivity<PayCostRcordPresenter> implements PayCostRcordContract.View {
        @BindView(R.id.recyclerView)
    XRecyclerView recyclerView;
        @BindView(R.id.toolbar)
    CustomToolbar toolbar;
    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerPayCostRcordComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .payCostRcordModule(new PayCostRcordModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_pay_cost_rcord; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        initRecycler();
        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                killMyself();
            }

            @Override
            public void onRightBack() {

            }
        });
    }

    /**
     * 初始化recycler
     */
    private void initRecycler() {
        List<String> list = new ArrayList<>();
        list.add("s");
        list.add("s");
        list.add("s");
        PayCostRecordAdapter adapter = new PayCostRecordAdapter(list);
        LinearLayoutManager lr = new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.VERTICAL,false);
        recyclerView.setLayoutManager(lr);
        ArmsUtils.configRecyclerView(recyclerView,lr);
        recyclerView.clearHeader();
        recyclerView.setPullRefreshEnabled(false);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new DefaultAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int viewType, Object data, int position) {
                startActivity(new Intent(PayCostRcordActivity.this,OrderDetailActivity.class));
            }
        });

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
}
